package cz.cuni.amis.episodic.bayes.memories.eval;

import java.util.Arrays;
import java.util.List;

import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import org.apache.commons.lang.StringUtils;

import cz.cuni.amis.episodic.bayes.memories.MemoryElement;

@Data
@RequiredArgsConstructor
public class SingleTestCasePerformance {
	/**
	 * Mems for the sequence.
	 */
	@NonNull
	List<MemoryElement> mems;

	/**
	 * Results for 0, 1 ... mems
	 */
	@NonNull
	List<RecallResult> results;

	/**
	 * performace[i] is percentage of correctly recalled actions when (i+1) mems
	 * were used.
	 */

	/**
	 * Number of mems on given level (G_i ... G_0, O)
	 */
	int[] memsOnLevel;

	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("MEMS");
		builder.append("\n");
		builder.append(StringUtils.join(mems, '\n'));
		builder.append("\n");
		builder.append("RECALLED");
		builder.append("\n");

		for (int i = 0; i < results.size(); i++) {
			builder.append(results.get(i).getPerformanceByLevel()[0]);
			builder.append(" -> ");
			builder.append(StringUtils.join(results.get(i).recall
					.getHierarchyByTime().get(0), '\t'));
			builder.append("\n");
		}

		return builder.toString();
	}

	public long getTotalComputationTimeNanos() {
		long sum = 0;
		for (MemoryElement mem : mems) {
			sum += mem.getTimeNanoToCompute();
		}
		return sum;
	}
}
